package com.viviet.mobileservices.dao.impl;

import java.util.List;

import org.hibernate.LockMode;

import com.viviet.mobileservices.dao.IVMCashflowDAO;
import com.viviet.mobileservices.dao.entity.VMCashflow;
import com.viviet.mobileservices.util.Logit;


/**
 * A data access object (DAO) providing persistence and search support for
 * BoCashflow entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see .BoCashflow
 * @author MyEclipse Persistence Tools
 */

public class VMCashflowDAO extends BaseHelperDAO implements IVMCashflowDAO {
	private static final Logit log = Logit.getInstance(VMCashflowDAO.class);
	// property constants
	public static final String CUSTOMER_ID = "customerId";
	public static final String EVENT_DATE = "eventDate";
	public static final String VALUE_DATE = "valueDate";
	public static final String CASHFLOW_TYPE = "cashflowType";
	public static final String CASHFLOW_AMOUNT = "cashflowAmount";
	public static final String CASH_BALANCE = "cashBalance";
	public static final String PRODUCT_ID = "productId";
	public static final String CURRENCY_CODE = "currencyCode";
	public static final String RATE = "rate";
	public static final String TAX = "tax";
	public static final String SOURCE_TYPE = "sourceType";
	public static final String SOURCE_ID = "sourceId";
	public static final String ACTIVE_FLAG = "activeFlag";

	public void save(VMCashflow transientInstance) {
		log.debug("saving BoCashflow instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(VMCashflow persistentInstance) {
		log.debug("deleting BoCashflow instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public VMCashflow findById(java.lang.String id) {
		log.debug("getting BoCashflow instance with id: " + id);
		try {
			VMCashflow instance = (VMCashflow) getHibernateTemplate().get("BoCashflow", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding BoCashflow instance with property: " + propertyName + ", value: " + value);
		try {
			String queryString = "from BoCashflow as model where model." + propertyName + "= ?";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCustomerId(Object customerId) {
		return findByProperty(CUSTOMER_ID, customerId);
	}

	public List findByEventDate(Object eventDate) {
		return findByProperty(EVENT_DATE, eventDate);
	}

	public List findByValueDate(Object valueDate) {
		return findByProperty(VALUE_DATE, valueDate);
	}

	public List findByCashflowType(Object cashflowType) {
		return findByProperty(CASHFLOW_TYPE, cashflowType);
	}

	public List findByCashflowAmount(Object cashflowAmount) {
		return findByProperty(CASHFLOW_AMOUNT, cashflowAmount);
	}

	public List findByCashBalance(Object cashBalance) {
		return findByProperty(CASH_BALANCE, cashBalance);
	}

	public List findByProductId(Object productId) {
		return findByProperty(PRODUCT_ID, productId);
	}

	public List findByCurrencyCode(Object currencyCode) {
		return findByProperty(CURRENCY_CODE, currencyCode);
	}

	public List findByRate(Object rate) {
		return findByProperty(RATE, rate);
	}

	public List findByTax(Object tax) {
		return findByProperty(TAX, tax);
	}

	public List findBySourceType(Object sourceType) {
		return findByProperty(SOURCE_TYPE, sourceType);
	}

	public List findBySourceId(Object sourceId) {
		return findByProperty(SOURCE_ID, sourceId);
	}

	public List findByActiveFlag(Object activeFlag) {
		return findByProperty(ACTIVE_FLAG, activeFlag);
	}

	public List findAll() {
		log.debug("finding all BoCashflow instances");
		try {
			String queryString = "from BoCashflow";
			return getHibernateTemplate().find(queryString);
			// return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public VMCashflow merge(VMCashflow detachedInstance) {
		log.debug("merging BoCashflow instance");
		try {
			VMCashflow result = (VMCashflow) getHibernateTemplate().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(VMCashflow instance) {
		log.debug("attaching dirty BoCashflow instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(VMCashflow instance) {
		log.debug("attaching clean BoCashflow instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}